<!--考核项详情-->
<template>
  <div id="cornerComment" v-if="dialogVisible">
    <div class="cornerComment-in" ref="dialogBox">
      <div class="cornerComment-in-title">
        <span>试用期考核项详情</span>
        <span class="el-icon-circle-close close-Btn-line" @click="closePOpup"></span>
      </div>
      <div class="commentBody">
        <div class="resruitment-title"><p>考核项</p></div>
        <div class="boxInterview">
          <!--本体列表，数据 -->
          <el-table
              ref="multipleTable"
              :data="arryList"
              :border="tableoption.tableBorder"
              tooltip-effect="dark">
            <el-table-column
                label="考核项"
                align="center"
                prop="content"
                :key="1">
            </el-table-column>
            <el-table-column
                label="考核限期"
                align="center"
                prop="end_time"
                :key="2">
            </el-table-column>
            <el-table-column
                label="状态"
                align="center"
                prop="status"
                :key="12">
              <template slot-scope="scope">
                {{ scope.row.is_examine == 0 ? '未评估' : (scope.row.is_examine == 1 ? '已评估（合格）' : '已评估（不合格）') }}

              </template>
            </el-table-column>
            <el-table-column
                label="操作"
                align="center"
                width="140"
                :key="13">
              <template slot-scope="scope">
                <el-button size="small" @click="AssessmentApprovalFn(scope.row)">
                  {{ scope.row.is_examine == 0 ? '考核评估' : '查看考核详情' }}
                </el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div class="resruitment-title"><p>录用审核意见</p></div>
        <div>
          <el-input
              type="textarea"
              :rows="4"
              placeholder="录用审核意见"
              v-model="employ_content">
          </el-input>
        </div>
        <div class="resruitment-title"><p>考核人会签</p>
          <el-button @click="signFn" size="mini" type="primary" plain>刷新</el-button>
        </div>
        <div class="boxInterview">
          <div class="signBox">
            <div class="signList" v-for="item in signList" :key="item.id">
              <img :src="item.pic" alt="" v-if="item.pic">
              <!--                <p>{{`${item.realname}（已会签）`}}</p>-->
              <p>
                <el-tag :type="item.is_autograph?'success':'danger'" @click="getAutogragh(item)">{{
                    item.realname
                  }}{{ item.is_autograph ? '（已会签）' : '（未会签）' }}
                </el-tag>
              </p>
            </div>
          </div>
        </div>
      </div>
      <div class="cornerComment-in-footer">
        <el-button @click="closePOpup" size="small">返回</el-button>
        <el-button type="primary" @click="getApproval(1)" size="small">批准录用</el-button>
        <el-button @click="getApproval(2)" size="small" type="danger" plain>不予录用</el-button>
      </div>
    </div>
    <!--    'assessmentId', 'resumeId'-->
    <!--    批复考核项-->
    <AssessmentApproval :visible.sync="approvalVisible" :assessmentId="assessmentId" :resumeId="resumeId"
                        :assessmentName="assessmentName" @InitFn="InitFn" :isExamine="is_examine"></AssessmentApproval>
    <!--    会签审核人 signType 1 面试签字 2 考核签字-->
    <autograghUser :visible.sync="autograghVisible" @signFn="signFn" :userOption="userOption"
                   :resumeId="resumeId" signType="2"></autograghUser>
  </div>
</template>

<script>
import AssessmentApproval from "./AssessmentApproval";
import {pagination, tableoption} from '@/utils/util.js'
import autograghUser from "./autograghUser";

export default {
  props: ['visible', 'resumeId'],
  components: {
    AssessmentApproval,
    autograghUser
  },
  data() {
    return {
      dialogVisible: false,
      arearBox: '',
      tableoption: tableoption,
      editId: this.$route.query,
      page: {
        pageindex: pagination.pageIndex,
        pagesize: pagination.pageSize,
        total: pagination.total
      },
      arryList: [],
      value1: '',
      navList: [],
      passTime: 0, // 合格时间
      joinTime: 0, // 参与时间
      approvalVisible: false,
      assessmentId: 0,
      assessmentName: '',
      is_examine: 0,
      signList: [],
      autograghVisible: false,
      userOption: null, // 签名人信息
      employ_content: ''
    }
  },
  watch: {
    visible() {
      this.dialogVisible = this.visible
      if (this.visible) {
        this.InitFn()
        this.signFn()
      } else {
        this.arryList = []
      }
    }
  },
  created() {
  },
  methods: {
    // 初始化
    async InitFn() {
      // <!--        resumeType 1 查看简历 2 待处理的简历 3 待面试简历 4 考核中的应聘者 5 一录用应聘者-->
      // p 	整型 	必填 	1 	- 	页码
      // rercuit_sn 	字符串 	必填 	1 	- 	招聘发布编号
      // title 	字符串 	必填 	1 	- 	招聘名称
      // name 	字符串 	必填 	1 	- 	面试人
      // mobile_phone 	字符串 	必填 	1 	- 	面试人电话
      // status 	字符串 	必填 	1 	- 	0待审核1通过2驳回
      // recruit_id
      let option = {
        p: this.page.pageindex,
        resume_id: this.resumeId // 简历id
      };
      console.log('option:', option)
      let data = await this.$fetch(this.api.recruit.examine.index, option);
      console.log('data:', data)
      this.arryList = data.list.data
      this.page.total = data.list.total
    },
    handleEdit(index) {
      this.$router.push('/CornerApplyHestoryDetail?id=' + this.arryList[index].id)
    },
    // 分页
    handleSizeChange(val) {
      this.page.pageindex = val
      this.InitFn()
    },
    showClassList(indexList, index) {
      this.$router.push('/CornerApplyHestoryDetail?corner_id=' + this.arryList[indexList].corner_id + '&class_id=' + this.arryList[indexList].apply_class[index].id)
    },
    // 关闭弹窗
    closePOpup() {
      this.$emit('update:visible', false)
    },
    AssessmentApprovalFn(option) {
      this.is_examine = option.is_examine
      this.assessmentName = option.content
      this.assessmentId = option.id;
      this.approvalVisible = true;
    },
    getApproval(option) {
      let n = this;
      if (option === 1) {
        //
        // this.$prompt('确认通过考核，填写考核备注', '提示', {
        //   confirmButtonText: '确认考核',
        //   cancelButtonText: '取消',
        // }).then(({value}) => {
        //   n.submitFromFn();
        // }).catch(() => {
        // });
        this.$confirm('确认通过考核, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          n.submitFromFn();
        }).catch(() => {
        });
      } else {
        if (!this.employ_content) {
          this.$message.error('填写审核意见')
          return
        }
        this.$confirm('驳回试用期考核, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          n.rejectFn();
        }).catch(() => {
        });
        // this.$prompt('驳回试用期考核，填写驳回备注', '提示', {
        //   confirmButtonText: '确定并保存',
        //   cancelButtonText: '取消',
        // }).then(({value}) => {
        //   console.log(value)
        //   n.rejectFn(value || '')
        // }).catch(() => {
        // });
      }
    },
    async rejectFn() {
      // , reject_data: option
      let data = await this.$post(this.api.recruit.examine.eliminate, {
        id: this.resumeId,
        employ_content: this.employ_content
      });
      console.log('data:', data)
      if (!data.code) {
        this.$message.success(data.msg)
        this.$emit('InitFn')
        this.closePOpup()
      } else {
        this.$message.error(data.msg)
      }
    },
    async submitFromFn() {
      // 此处需要判断考核项是否有
      // 签名是否都有
      if (!this.arryList.length) {
        this.$message.error('考核项至少一项')
        return
      }
      let status = 1
      for (let i in this.arryList) {
        if (!this.arryList[i].is_examine) {
          status = 0
        }
      }
      if (!status) {
        this.$message.error('考核项还未评估完无法提交')
        return
      }
      let statusSign = 1
      for (let i in this.signList) {
        if (!this.signList[i].pic) {
          statusSign = 0
        }
      }
      if (!statusSign) {
        this.$message.error('审核人未签名确认')
        return
      }
      // 提交面试审核
      let data = await this.$post(this.api.recruit.examine.employ, {
        id: this.resumeId,
        employ_content: this.employ_content
      });
      if (!data.code) {
        this.$message.success(data.msg)
        this.$emit('InitFn')
        this.closePOpup()
      } else {
        this.$message.error(data.msg)
      }
    },
    async signFn() {
      let data = await this.$fetch(this.api.recruit.examine.autograph, {id: this.resumeId});
      if (!data.code) {
        console.log('请求会签:', data)
        this.signList = this.getJson(data.list)
      }
    },
    getJson(option) {
      return JSON.parse(JSON.stringify(option))
    },
    getAutogragh(option) {
      this.userOption = this.getJson(option);
      this.autograghVisible = true;
    }
  },
  mounted() {
  }
}
</script>
<style scoped>
#cornerComment {
  height: 100vh;
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9;
}

.cornerComment-in {
  width: 80%;
  height: 70%;
  background: #fff;
  display: flex;
  flex-direction: column;
  border-radius: 5px;
}

.cornerComment-in-title {
  height: 50px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ddd;
  font-size: 24px;
}

.cornerComment-in-title span {
  padding: 0 10px;
}

.cornerComment-in-title span:first-child {
  flex: 1;
  font-size: 16px;
}

.cornerComment-in-footer {
  height: 50px;
  border-top: 1px solid #ddd;
  display: flex;
  align-items: center;
  padding: 0 10px;
  justify-content: center;
}

.commentBody {
  padding: 10px;
  flex: 1;
  overflow-y: auto;
}

.close-Btn-line {
  cursor: pointer;
}

.toolbarLine {
  text-align: center;
}

.resruitment-title {
  padding: 20px 0 5px;
  border-bottom: 2px solid #abd3f3;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
}

.resruitment-title p {
  flex: 1;
}

.boxInterview {
  padding: 0 20px;
}

.tagBox {
  cursor: pointer;
}

.signBox {
  display: flex;
  align-items: center;
}

.signList {
  flex: 1;
  text-align: center;
  text-align: center;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.signList img {
  width: 200px;
  display: block;
  border: 1px solid #f4f4f4;
  margin-bottom: 10px;
}

.el-tag {
  cursor: pointer;
}
</style>


